package com.dusk.util
{
    public final class TimeUtil extends UtilBase
	{
		public function TimeUtil()
		{
		}
		
		/**
		 * 获取当前日期
		 * @param split 分隔符，默认-
		 * @return 指定日期，可参与日期间隔运算
		 */
		public static function getCurrentDate(split:String = "-"):String
		{
			var date:Date = new Date();
			return (date.fullYear.toString() + split + (date.month + 1).toString() + split + date.date.toString());
		}
		
		/**
		 * 获取当前时间
		 * @param split 分隔符，默认-
		 * @return 指定时间
		 */
		public static function getCurrentTime(split:String = ":"):String
		{
			var date:Date = new Date();
			return StringUtil.completeZeroFormat(date.hours) + split + StringUtil.completeZeroFormat(date.minutes) + split + StringUtil.completeZeroFormat(date.seconds);
		}
		
		/**
		 * 获取两个日期间的天数
		 * @param timeString1 前一天
		 * @param timeString2 后一天
		 * @param split 分隔符，默认-
		 * @return 后一天与前一天的间隔天数
		 */
		public static function getDayBetweenTwoDate(timeString1:String, timeString2:String,split:String = "-"):int
		{
			var arr1:Array = timeString1.split(split);
			var year1:uint = int(arr1[0]);
			var month1:uint = int(arr1[1]) - 1;
			var day1:uint = int(arr1[2]);
			
			var arr2:Array = timeString2.split(split);
			var year2:uint = int(arr2[0]);
			var month2:uint = int(arr2[1]) - 1;
			var day2:uint = int(arr2[2]);
			
			var date1:Date = new Date(year1, month1, day1);
			var date2:Date = new Date(year2, month2, day2);
			
			return int((date2.getTime() - date1.getTime()) / 1000) / 3600 / 24;
		}
	}
}
